package com.imc.core.utils;

import com.imc.platform.base.role.dao.IRoleMapper;
import com.imc.platform.base.user.dao.mapper.IUserMapper;
import com.imc.platform.base.user.pojo.User;
import com.imc.platform.frame.mapper.ICommonMapper;
import com.netflix.ribbon.proxy.annotation.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.misc.Contended;

import java.util.List;

/**
*类描述：mysql工具类
*开发者：QY
*创建时间：2018/9/10 15:50
**/
@Component
public class MysqlUtil {

    @Autowired
    ICommonMapper commonMapper;

    @Autowired
    IUserMapper userMapper;

    /**
    *QY 2018/9/10 15:50
    *方法描述：获取数据库表最大ID，每次调取不管后续操作成不成功，最大ID都不会回滚
    **/
    public String getMaxId(String tableName) {
        String maxId=commonMapper.getMaxId(tableName);
        if(null == maxId || maxId.equals(null)){
            maxId = "1";
            commonMapper.setMaxId(maxId,tableName);
        }else{
            commonMapper.updateMaxId(maxId,tableName);
        }
        return maxId;
    }

    /*
    * YT  2018/10/22 13:17
    * 方法描述：获取自增长ID
    */
    public int getAutoInsertId(){
        return commonMapper.getAutoInsertId();
    }

    /**
     * 方法描述: 根据登陆名称获取用户信息
     * SJC 2018-9-13 16:00:37
     *
    */
    public User getUserByLoginName(String loginName){
        List<User> users = userMapper.queryUserByLoginName(loginName);
        User user = null;
        if(users != null && ((List) users).size()>0){
            user = users.get(0);
        }
        return user;
    }

    /**
     * 方法描述: 根据登陆名称获取用户信息
     * SJC 2018-9-13 16:00:37
     *
     */
    public User getUserByLoginNameCommon(String loginName){
        List<User> users = userMapper.queryUserByLoginNameCommon(loginName);
        User user = null;
        if(users != null && ((List) users).size()>0){
            user = users.get(0);
        }
        return user;
    }

}
